package top.fzqblog.kotlinapp.func

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.util.Log
import android.widget.Toast
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import top.fzqblog.kotlinapp.app.KotlinApp
import top.fzqblog.kotlinapp.util.Constants

/**
 * Created by 抽离 on 2017/11/14 0014.
 */
fun toast(msg:String, length:Int = Toast.LENGTH_SHORT){
    Toast.makeText(KotlinApp.instance, msg, length).show()
}

inline  fun <reified T: Activity> Context.startActivity(vararg params: Pair<String, Any>){
    val intent = Intent(this, T::class.java)
    log(params.toString())
    params.forEach{
        log("first:${it.first}-----------second:${it.second}")
        when(it.second){
            is String -> intent.putExtra(it.first, it.second as String)
            is Long ->  intent.putExtra(it.first, it.second as Long)
        }
    }
    startActivity(intent)
}


fun log(msg: String, tag: String = Constants.tag){
    Log.i(tag, msg)
//        Log.i(javaClass.simpleName, msg)
}

fun <T> Observable<T>.applySchedulers(): Observable<T> {
    return subscribeOn(Schedulers.io()).
            unsubscribeOn(Schedulers.io()).
            observeOn(AndroidSchedulers.mainThread())
}